package com.api.test;

import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.factory.InitializingBean;

public class SystemProperyInitializer implements InitializingBean {

	private Map<String, String> properties;

	private boolean overrideProperties = false;

	@Override
	public void afterPropertiesSet() throws Exception {

		if (properties != null) {

			for (Entry<String, String> entry : properties.entrySet()) {

				if (overrideProperties || System.getProperty(entry.getKey()) == null) {

					System.setProperty(entry.getKey(), entry.getValue());
				}
			}
		}
	}

	public void setProperties(Map<String, String> properties) {
		this.properties = properties;
	}

	public void setOverrideProperties(boolean value) {
		this.overrideProperties = value;
	}
}
